﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 工序管理新增页面 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
</head>
<body class="layui-padding-3">
    <h3 style="color: #34c38f">
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/Process/ProcessList'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;工序&nbsp;<span style="color: #000">(状态码)</span>
    </h3>
    <hr style="color: #34c38f" />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <label class="layui-form-label">工序编码:</label>
            <input type="text"
                   id="ProcessNumber"
                   lay-verify="required"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 400px" 
                   />
        </div>
    </div>
    <div style="margin-left: 600px; margin-top: -50px">
        <div class="layui-input-block">
            <label class="layui-form-label">工序名称:</label>
            <input type="text"
                   id="ProcessName"
                   lay-verify="required"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 400px" 
                   />
        </div>
    </div>
    <br />
    <br />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <label class="layui-form-label">工作中心:</label>
            <select name="WorkCenter" id="workCenterCode" lay-filter="aihao" style="width: 400px" onchange="change()">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>

    <div style="margin-left: 600px; margin-top: -50px">
        <div class="layui-input-block">
            <label class="layui-form-label">状态:</label>
            <select name="interest" lay-filter="aihao" style="width: 400px" id="ProcessState">
                <option value=true>有效</option>
                <option value=false>无效</option>
            </select>
        </div>
    </div>
    <br />
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 1000px"
                    type="submit"
                    class="layui-btn"
                    lay-submit
                    lay-filter="demo1"
                    onclick="ProcessAdd()">
                保存<i class="layui-icon layui-icon-list"></i>
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 1000px"
                    type="submit"
                    class="layui-btn layui-bg-blue"
                    lay-submit
                    lay-filter="search">
                提交<i class="layui-icon layui-icon-right"></i>
            </button>
        </div>
    </div>
    <h3 style="color: #50a5f1">所需资源行</h3>
    <hr />
    <h4>行信息</h4>
    <div class="layui-btn-container">
        <button style="margin-left: 1100px"
                type="submit"
                class="layui-btn layui-bg-blue"
                lay-on="test-page-custom" >
            <span><i class="layui-icon layui-icon-addition"></i>新增资源</span>
        </button>
    </div>

    <script>
        function change() {
            var workid = $("#workCenterCode").val();
            var ProcessNumber = $("#ProcessNumber").val();
            localStorage.setItem("workid", workid);
            localStorage.setItem("ProcessNumber", ProcessNumber);
        }
      
        //工作中心下拉框
        WorkList()
        function WorkList() {
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/Process/WorkCenterList",
                data: JSON.stringify({}),
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => { 
                    console.log(res);
                    $.each(res.data, function () {
                        $("#workCenterCode").append(`<option value="${this.workCenterCode}">${this.workCenterName}</option>`);
                    })
                },
            })
        }
        //工序新增
        function ProcessAdd() {
            var data = {
                ProcessNumber: $("#ProcessNumber").val(),
                ProcessName: $("#ProcessName").val(),
                WorkCentreCode: $("#workCenterCode").val(),
                ProcessState: $("#ProcessState").val() == 'true',
            }
            console.log(data)
            localStorage.setItem("ProcessNumber",data.ProcessNumber)
            $.post({
                url: '@ViewBag.RBACWrite' + "/api/Process/ProcessAdd",
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 1) {
                        layer.alert("新增成功");
                        return;
                    }
                    else {
                        layer.alert("新增失败");
                        return;
                    }
                }
            })
        }
    </script>
    <table class="layui-hide" id="ID-table-demo-search"></table>
    <script>


        layui.use('table', function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;

            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 2,
                        title: '资源行添加',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '600px'],
                        content: '/Process/ResouresAdd',
                        end: function () { // 弹出层关闭后执行的回调
                            formData.ProcessNumber= $("#ProcessNumber").val(),
                                console.log(formData.ProcessNumber)
                            Seach()
                        },
                    });
                },
            });
            var formData = {
                ProcessNumber:""
            };
          
            if (formData.ProcessNumber != "") { 
                Seach()
            }
          

            // 提交事件
            form.on('submit(search)', function (data) {
                var field = data.field; // 获取表单字段值
                // 显示填写结果，仅作演示用
                formData.ProcessNumber = $("#ProcessNumber").val()
                Seach();
                return false; // 阻止默认 form 跳转
            });


            // 搜索提交
            function Seach() {
                console.log(formData);
                var WareNum = "http://localhost:5159/api/Process/ProcessDetailList?Number=" + formData.ProcessNumber;
                $.ajax({
                    url: WareNum,
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [
                                [
                                    { type: 'checkbox', title: '复选框', fixed: true }, // 单选框
                                    { field: 'processDetailId', title: '序号', width: 80 },
                                    { field: 'processDetailId', title: '资源编码', width: 120 },
                                    { field: 'resourceName', title: '资源名称', width: 120 },
                                    { field: 'processDetailUnitsName', title: '资源单位', width: 100 },
                                    { field: 'processDetailDosage', title: '资源用量', width: 100 },
                                    { field: 'unitsPrice', title: '单位成本', width: 100 },
                                    { field: 'createTime', title: '创建时间', width: 100 },
                                    { field: '', title: '创建人', width: 100 },
                                    { field: 'processDetailStateName', title: '状态', width: 100 },
                                    {
                                        fixed: 'right',
                                        title: '操作',
                                        width: 134,
                                        minWidth: 125,
                                        templet: '#toolDemo',
                                    },
                                ],
                            ],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        
                        return;

                    }
                });
               
            };
        });
    </script>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="" style="color:cornflowerblue;">编辑</a>
          <br />
          <a onclick="" style="color:red">删除</a>
        </div>
    </script>
</body>
</html>

